package router

import (
	"github.com/gin-contrib/multitemplate"
	v1 "gitee.com/colzry/gin-postgres/api/v1"
	"gitee.com/colzry/gin-postgres/utils"
	"github.com/gin-gonic/gin"
)

func createMyRender() multitemplate.Renderer {
	p := multitemplate.NewRenderer()
	p.AddFromFiles("front", "web/front/dist/index.html")
	return p
}

func InitRouter() {
	gin.SetMode(utils.RunMode)
	r := gin.New()
	_ = r.SetTrustedProxies(nil)

	r.HTMLRender = createMyRender()
	r.Static("/front", "./web/front/dist")
	r.GET("/", func(c *gin.Context) {
		c.HTML(200, "front", nil)
	})
	
	router := r.Group("api/v1")
	{
		router.POST("user/add", v1.AddUser)
		router.GET("user/:id", v1.GetUserInfo)
		router.GET("user/users", v1.GetUsers)
		router.DELETE("user/:id", v1.DeleteUser)
		router.PUT("user/update", v1.EditUser)
	}

	_ = r.Run(utils.HTTPPort)

}